package cn.wuyu.baselibrary.net.http

/**
 * APP异常
 */
class HttpException//	public static Object data;
private constructor(detailMessage: String) : RuntimeException(detailMessage) {

    constructor(resultCode: String, detailMessage: String) : this(getExceptionMessage(resultCode, detailMessage)) {}

    companion object {
        private const val serialVersionUID = 7144897636394186929L
        lateinit var errorCode: String
        lateinit var message: String
        /**
         * 对errorCode进行封装处理
         */
        private fun getExceptionMessage(resultCode: String, detailMessage: String): String {
            errorCode = resultCode
            when (resultCode) {
                /*-----------以下是后台定义的公共错误----------*/
                "00-000001" -> message = "配置键不存在"
                "00-000002" -> message = "系统异常"
                "00-000003" -> message = "参数错误"
                "00-000004" -> message = "非法请求"
                "00-000005" -> message = "字段不存在"
                "00-000006" -> message = "参数不能为空"
                "00-000007" -> message = "验证字段参数只能为一个"
                "00-000008" -> message = "验证字段参数类型只能为{}"
                "00-000009" -> message = "订单已关闭"
                "00-000010" -> message = "用户已存在"
                "00-000011" -> message = "==="
                "00-000012" -> message = "手机号已存在"
                "00-000013" -> message = "手机号不正确"
                "00-000014" -> message = "手机号长度不正确"
                "00-000015" -> message = "身份证已存在"
                "00-000016" -> message = "身份证不存在"
                "00-000017" -> message = "身份证不正确"
                "00-000018" -> message = "身份证长度不正确"
                "00-000019" -> message = "排序类型不能为空"
                "00-000020" -> message = "排序顺序不能为空"
                "00-000021" -> message = "参数不能为空"
                "00-000022" -> message = "支付密码错误次数达到上限"
                "00-000023" -> message = "订单信息错误"
                "00-000024" -> message = "参数取值范围错误"
                "00-000025" -> message = "参数长度范围错误"
                "00-000026" -> message = "参数规则不匹配"
                "00-000027" -> message = "Redis Key不存在"
                "00-000028" -> message = "请求URL不能存在多个"
                "00-000029" -> message = "请求方法不能存在多个"
                "00-000030" -> message = "请求方法不支持"
                "00-000031" -> message = "在{}类中ID不存在"
                "00-000032" -> message = "事物暂时不支持操作"
                "00-000033" -> message = "未知类型"
                "00-000034" -> message = "未实现功能"
                "00-000035" -> message = "系统异常"
                "00-000036" -> message = "请求前缀没有设置"
                "00-000037" -> message = "数据不存在"
                "00-000038" -> message = "没有可用的积分币"
                "00-000039" -> message = "订单不存在"
                "00-000040" -> message = "交易类型错误"
                "00-000041" -> message = "用户账户信息不存在"
                "00-000042" -> message = "订单已完成"
                else -> message = detailMessage
            }

            return message
        }
    }
}
